package com.hiwan.system.service.menu;

import java.util.HashMap;
import java.util.Map;
import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hiwan.platform.util.StackTraceUtil;

/**
 * 
 * Datetime   ： 2013-2-21 上午11:57:54<br>
 * Title      :  MenuPojo2Map.java<br>
 * Description:   <br>
 * Copyright  :  Copyright (c) 2011<br>
 * Company    :  pshiwan<br>
 * @author bsl
 *
 */
public class MenuPojo2Map {
	private static Logger logger = LoggerFactory.getLogger(MenuPojo2Map.class);

	public static Map<String, Object> getMap(Object pojo) {
		Map<String, Object> pojoMap = new HashMap<String, Object>();
		String key;
		int index;
		try {
			Class<? extends Object> c = pojo.getClass();
			Method m[] = c.getDeclaredMethods();
			for (int i = 0; i < m.length; i++) {
				if (m[i].getName().indexOf("get") == 0) {
					index = m[i].getName().indexOf("get");
					key = m[i].getName().substring(index + 3);
					pojoMap.put(key, m[i].invoke(pojo, new Object[0]));
				}
			}
		} catch (Throwable e) {
			logger.error(StackTraceUtil.getStackTrace(e));
		}
		return pojoMap;
	}
}
